<?php

namespace App\Models;

use App\Enums\AuthType;
use BenSampo\Enum\Traits\CastsEnums;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @mixin IdeHelperRegistryAuth
 */
class RegistryAuth extends BaseModel
{
    use CastsEnums;
    use SoftDeletes;

    protected $appends = [
        'display_no',
    ];

    protected $casts = [
        'auth_type' => AuthType::class,
    ];

    public function user()
    {
        return $this->belongsTo(FrontendUser::class);
    }

    public function getDisplayNoAttribute()
    {
        return $this->auth_type->is(AuthType::PERSONAL()) ? $this->id_card_no : $this->license_no;
    }

    public function toSimpleArray()
    {
        return [
            'id' => $this->id,
            'name' => $this->auth_name,
            'type' => $this->auth_type->value,
            'display_no' => $this->display_no,
        ];
    }
}
